package cn.bonoon.controllers.fmm;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bonoon.core.plugins.AccountService;
import cn.bonoon.entities.AccountEntity;
import cn.bonoon.kernel.web.ButtonEventType;
import cn.bonoon.kernel.web.annotations.grid.GridStandardDefinition;
import cn.bonoon.kernel.web.controllers.AbstractGridController;
import cn.bonoon.kernel.web.controllers.GridButtonStatus;

@Controller
@RequestMapping("s/sys/account")
public class AccountController extends AbstractGridController<AccountEntity, AccountItem> {
	private final AccountService service;
	
	@Autowired
	public AccountController(AccountService service) {
		super(service);
		this.service = service;
	}

	@Override
	@GridStandardDefinition(
			insertClass = AccountInsert.class, 
			updateClass = AccountUpdate.class, 
			detailClass = AccountDetail.class
			)
	protected AccountService initLayoutGrid(LayoutGridRegister register) throws Exception {
		//分配角色
		register.button("分配角色", "roles.do", ButtonEventType.DIALOG).ordinal(21);
		register.button("分配用户组", "groups.do", ButtonEventType.DIALOG).ordinal(22);
		//重置密码
		register.button("重置密码", "resetpwd.do", ButtonEventType.DIALOG).ordinal(41);
		register.button("绑定", "thirds.do", ButtonEventType.DIALOG).title("绑定第三方的账户(如：QQ、微信、新浪等)。").ordinal(40);
		
		register.button("代管策略", "proxy.do", ButtonEventType.DIALOG).status(GridButtonStatus.valueOf("proxyable", 1)).ordinal(30);
		register.button("访问策略", "access.do", ButtonEventType.DIALOG).ordinal(31);
		
		return service;
	}

	@Override
	protected Class<AccountItem> itemClass() {
		return AccountItem.class;
	}
}
